﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;

namespace DAO
{
   public class ChiTietPhieuDatPhongDAO
    {
       public List<ChiTietPhieuDatPhongDTO> DanhSachChiTietPhieuDatPhong()
       {
           List<ChiTietPhieuDatPhongDTO> kq = new List<ChiTietPhieuDatPhongDTO>();
           DataProvider dp = new DataProvider();
           dp.Connect();
           string strsql = "select*from ChiTietPhieuDatPhong";
           SqlDataReader dr = dp.ExecuteQuery(strsql);
           if (dr.HasRows)
           {
               while (dr.Read())
               {
                   ChiTietPhieuDatPhongDTO ct = new ChiTietPhieuDatPhongDTO();
                   ct.P_ID = int.Parse(dr["P_ID"].ToString());
                   ct.PDP_ID = int.Parse(dr["PDP_ID"].ToString());
                   ct.SoNguoi = int.Parse(dr["SoNguoi"].ToString());
                   kq.Add(ct);
               }
           }
           dp.Disconnect();
           return kq;          
       }
       public Boolean ThemChiTietPhieuDatPhong(ChiTietPhieuDatPhongDTO ct)
       {
           Boolean kq = false;
           DataProvider dp = new DataProvider();
           dp.Connect();
           string strsql = "insert into ChiTietPhieuDatPhong(P_Id,PDP_ID,SoNguoi)";
           strsql += "values(" + ct.P_ID + "," + ct.PDP_ID + "," + ct.SoNguoi + ")";
           int i = dp.ExecuteNonQuery(strsql);
           dp.Disconnect();
           if (i != 0)
               kq = true;
           return kq;
       }
       public Boolean XoaChiTietPhieuDatPhong(ChiTietPhieuDatPhongDTO ct)
       {
           Boolean kq = false;
           DataProvider dp = new DataProvider();
           dp.Connect();
           string strsql = "delete from ChiTietPhieuDatPhong where P_ID="+ct.P_ID +" and PDP_ID="+ct.PDP_ID;
           int i = dp.ExecuteNonQuery(strsql);
           dp.Disconnect();
           if (i != 0)
               kq = true;
           return kq;
       }
       public Boolean CapNhatChiTietPhieuDatPhong(ChiTietPhieuDatPhongDTO ct)
       {
           Boolean kq = false;
           DataProvider dp = new DataProvider();
           dp.Connect();
           string strsql = "update ChiTietPhieuDatPhong set SoNguoi=" + ct.SoNguoi + " where P_ID=" + ct.P_ID + " and PDP_ID=" + ct.PDP_ID;
           int i = dp.ExecuteNonQuery(strsql);
           dp.Disconnect();
           if (i != 0)
               kq = true;
           return kq;
       }
    }
}
